<?php
header( 'Content-Type: text/html; charset=utf-8' );
/*
 * Created on 24. mars. 2008
 */

setlocale(LC_TIME, "no_NO");
require_once('needed.php');

require_once("smarty/core/libs/Smarty.class.php");
$smarty = new Smarty();
$smarty->template_dir = "view/templates";
$smarty->compile_dir  = "smarty/compiled";
$smarty->cache_dir    = "smarty/cached";
$smarty->config_dir   = "smarty/configs";
$smarty->assign("charset", 'utf-8');
$smarty->caching = 0;
 

// page & controller
if(isset($_GET["page"])) $page = htmlentities($_GET["page"]);
else $page = "index";

$smarty->assign("page", $page);

$controller_class = "${page}";
$controller_file  = "controller/$page.controller.php";
$css_file         = "view/css/$page.css";

if (file_exists($controller_file)) {
	require_once($controller_file);
	$controller = new $controller_class();
	if (file_exists("view/templates/$page.tpl")){
		$smarty->assign("content_tpl", "$page.tpl");
	} else {
		die("template $page is missing");
	}
	if (file_exists($css_file)){
		$smarty->assign("css", $css_file);
	}
	$controller->prepare_model_and_view($_GET, $smarty);
} else {
	$smarty->assign("content_tpl", "error.tpl");
	$smarty->assign("message", "Controlleren '$page' finnes ikke");
}

$smarty->display("layout.tpl");
 
 
?>

